package com.hyzs.controller;

import com.hyzs.service.FulltextService;
import com.hyzs.service.GraphService;
import com.hyzs.service.RawDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class GraphController {


    @Autowired
    @Qualifier("neo4JService")
    private GraphService graphService;

    @Autowired
    private RawDataService rawDataService;

    // NOTE: EsService.gJQueryContentLabels not available.
    @Autowired
    @Qualifier("esService")
    private FulltextService fulltextService;

    @GetMapping("/getSomeNodes")
    public List<Map<String, Object>> getSomeNodes(@RequestParam(value="limit", defaultValue="30") String limit) {
        return graphService.getSomeData(limit);
    }

    @GetMapping("/getLawByName")
    public List<Map<String,Object>> getLawByName(@RequestParam(value = "name", defaultValue = "刑法") String name,
                                                 @RequestParam(value="limit", defaultValue="30") String limit){
        return graphService.getLawByName(name, limit);
    }

    @GetMapping("/getLawTree")
    public Map<String,Object> getLawTree(@RequestParam(value = "name", defaultValue = "中华人民共和国刑法") String name){
        return graphService.getLawTree(name);
    }

    @GetMapping("/getRelativeLaws")
    public List<Map<String,Object>> getRelativeLaws(@RequestParam(value = "names") String names,
                                                    @RequestParam(value="topK", defaultValue="10") String topK){
        return graphService.getRelativeLaws(names, topK);
    }

    @PostMapping(value = "/getSimJudgements")
    @ResponseBody
    public List<Map<String, Object>> getSimJudgements(@RequestBody Map<String, Object> param){
        String topKstr = "10";
        if(param.containsKey("topK")){
            topKstr = param.get("topK").toString();
        }
        return graphService.getSimJudgements( param.get("content").toString(), topKstr);
    }

    @PostMapping(value = "/getJudgementLaws")
    @ResponseBody
    public List<Map<String,Object>> getJudgementLaws(@RequestBody Map<String, Object> param){
        return graphService.getJudgementLaws(param.get("content").toString());
    }

    // graphService has no html_content.
    @GetMapping(value = "/getJudgementContent")
    @ResponseBody
    public Map<String,Object> getJudgementContent(@RequestParam(value = "doc_id") String doc_id){
        return rawDataService.getJudgementContentById(doc_id);
    }

    // graphService has no html_content.
    @PostMapping(value = "/getJudgementContentBatch")
    @ResponseBody
    public List<Map<String,Object>> getJudgementContent(@RequestBody Map<String, Object> param){
        List<String> doc_ids = (List<String>)param.get("doc_ids");
        return rawDataService.getJudgementContentByIds(doc_ids);
    }

    @GetMapping(value = "/availableLabels")
    @ResponseBody
    public Map<String,Object> availableLabels(){
        return fulltextService.availableLabels();
    }

    @PostMapping(value = "/queryContentLabels")
    @ResponseBody
    public Map<String,Object> queryContentLabels(@RequestBody Map<String, Object> param){
        int topK = 1;
        if(param.containsKey("topK")){
            topK = Integer.parseInt(param.get("topK").toString());
        }
        return fulltextService.queryContentLabels(param.get("content").toString(), param.get("label_name").toString(), topK);
    }

    @PostMapping(value = "/queryContentLabelArray")
    @ResponseBody
    public Map<String,Object> queryContentLabelArray(@RequestBody Map<String, Object> param){
        return fulltextService.queryContentLabelByCrimes(param.get("content").toString(), (List<String>)param.get("labels"));
    }

    @PostMapping(value = "/GJqueryContentLabels")
    @ResponseBody
    public Map<String,Object> gJQueryContentLabels(@RequestBody Map<String, Object> param){
        return fulltextService.gJQueryContentLabels(param.get("content").toString(), (List<String>)param.get("label_name"));
    }

/*
    @RequestMapping("/getJudgements")
    public List<Map<String,Object>> getJudgementByTitle(@RequestParam(value = "title", defaultValue = "刑事判决书") String name,
                                                      @RequestParam(value="limit", defaultValue="3") String limit){
        return graphService.getJudgementByTitle(name, limit);
    }

    @RequestMapping("/getJudgementsByLaw")
    public List<Map<String,Object>> getJudgementByLaw(@RequestParam(value = "name", defaultValue = "刑法") String name,
                                                      @RequestParam(value="limit", defaultValue="3") String limit){
        return graphService.getJudgementByLaw(name, limit);
    }

    @RequestMapping("/getSimJudgements")
    public List<Map<String,Object>> getRelativeCasesByTitle(@RequestParam(value = "title") String title,
                                                            @RequestParam(value="topK", defaultValue="3") String topK) {
        return graphService.getRelativeCasesByTitle(title, topK);
    }

    @RequestMapping("/getSimJudgementsByIds")
    public List<Map<String,Object>> getRelativeCasesByIds(@RequestParam(value = "ids") String ids,
                                                            @RequestParam(value="topK", defaultValue="3") String topK) {
        return graphService.getRelativeCasesByIds(ids, topK);
    }


    */





}